<template>
	<view class="main">
		<view class="class-list">
			<view class="item" @click="subject(item,index)" v-for="(item,index) in list" :key="index">
				<view class="title">
					<text class="spot"></text> <text class="content"> {{item.class}}</text>
				</view>
				<view class="value">
					共{{item.count}}题
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		subjectType
	} from "@/api/index.js"
	export default {
		data() {
			return {
				subjectType: '',
				resource: '',
				list: [],
			};
		},
		onLoad(option) {
			this.subjectType = option.subjectType
			this.resource = option.resource
		},
		mounted() {
			subjectType({
				subject: this.subjectType
			}).then(res => {
				this.list = res.data
			})
		},
		methods: {
			subject(item, index) {
				if (item.count == 0) {
					uni.showToast({
						icon: 'none',
						title: '当前分类没有题目可答'
					})
					return
				}
				uni.navigateTo({
					url: "/pages/subject/practiceSub?class=" + item.class + "&subjectType=" + this.subjectType +
						"&resource=" + this.resource + "&vip=0&index=" + index
				})
			}
		}
	}
</script>

<style lang="scss">
	.main {
		background-color: #F6F6F6;

		.class-list {
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			padding: 26rpx;
			justify-content: space-between;

			.item {
				background-color: #fff;
				border-radius: 12rpx;
				padding: 10rpx 20rpx;
				box-sizing: border-box;
				margin-bottom: 26rpx;
				width: calc(50% - 13rpx);
				height: 220rpx;
				position: relative;

				.title {
					font-size: 30rpx;
					color: #303030;
					display: flex;
					align-items: baseline;

					.spot {
						background-color: #F0F0F0;
						width: 20rpx;
						height: 20rpx;
						display: block;
						margin-right: 10rpx;
						border-radius: 100%;
					}

					.content {
						flex: 1;
					}

					.h1 {
						flex: 1;
					}
				}

				.value {
					color: #5E626B;
					font-size: 24rpx;
					position: absolute;
					left: 20rpx;
					bottom: 20rpx;
				}
			}
		}
	}
</style>